package cn.mybatishelper.handler;

import cn.mybatishelper.entity.CreateFile;
import cn.mybatishelper.entity.database.DatabaseEntity;
import cn.mybatishelper.exception.MybatisHelperException;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 处理程序公共父类
 * User: GameKing
 */
public abstract class AbstractHandler implements Handler {
    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractHandler.class);
    /**
     * 需要生成的数据实例list
     */
    protected List<DatabaseEntity> entities;
    /**
     * 要生成的文件实体的集合
     */
    protected List<CreateFile> fileEntities;

    protected AbstractHandler() {
    }

    protected AbstractHandler(List<DatabaseEntity> entities, List<CreateFile> fileEntities) {
        this.entities = entities;
        this.fileEntities = fileEntities;
    }

    @Override
    public boolean validate() throws MybatisHelperException {
        if (CollectionUtils.isEmpty(entities)) {
            LOGGER.error("数据库实例集合不能为null");
            return false;
        }
        if (CollectionUtils.isEmpty(fileEntities)) {
            LOGGER.error("文件实例集合不能为null");
            return false;
        }
        return true;
    }

    public List<DatabaseEntity> getEntities() {
        return entities;
    }

    public void setEntities(List<DatabaseEntity> entities) {
        this.entities = entities;
    }

    public List<CreateFile> getFileEntities() {
        return fileEntities;
    }

    public void setFileEntities(List<CreateFile> fileEntities) {
        this.fileEntities = fileEntities;
    }
}
